/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package neuronalenetzeelearning.view.controlpanel;

import neuronalenetzeelearning.view.gui.*;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import neuronalenetzeelearning.model.Graph;
import neuronalenetzeelearning.view.help.HelpPanel;
import neuronalenetzeelearning.view.help.HelpWindowFactory;
/**
 *
 * @author Henning
 */
public class StepModeChooserPanel extends GraphPanelProperty {
    JComboBox learningRuleChooser = new JComboBox();

    public StepModeChooserPanel(){

        super();
        this.setBackground(background);
        this.setLayout(grid);
        this.setBorder(javax.swing.BorderFactory.createTitledBorder("Wählen Sie den Ausführmodus für Ihr Neuronale Netz!"));

        //Set the look and feel
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.gridheight = 1;
        constraints.gridx = 1;
        constraints.gridy = 1;

        JLabel bord = new JLabel("--------------------------------------------------------------------------------------------------------");
        add(bord, constraints);

        constraints.gridwidth = GridBagConstraints.RELATIVE;
        constraints.gridheight = 1;
        constraints.gridx = 1;
        constraints.gridy = 2;

        add(new JLabel("Schrittmodus"), constraints);

        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.gridheight = 1;
        constraints.gridx = 2;
        constraints.gridy = 2;

        learningRuleChooser.setModel(new DefaultComboBoxModel(new String[] { "Schrittweise", "n - Schritte", "Durchlauf" }));
        this.add(learningRuleChooser, constraints);


        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridheight = 1;
        constraints.gridx = 1;
        constraints.gridy = 3;

        JLabel Hint = new JLabel();
        Hint.setText("<html><ul>"
                //+ "<ol>"
                + "Wenn du mehrere Eingabevektoren (EV) ausgewählt hast, vergiss nicht, dass"
                + " vor jedem Lernschritt zufällig einer der Eingabevektoren ausgewählt wird."
                + " Da das Netz aber alle Vektoren gleichzeitig lernen soll, muss die Gewichtsmatrix"
                + " über einen längeren Zeitraum, in dem wahrscheinlich alle Vektoren mindestens"
                + " einmal verwendet wurden, stabil blieben.</>"
                + "<ol>"
                +"Hier gilt beim Lernen:"
                +"<ul>"
                +"<li>1 EV => mind. 2 Schritte</li>"
                +"<li>2 EV => mind. 6 Schritte</li>"
                +"<li>3 EV => mind. 10 Schritte</li>"
                +"<li>4 EV => mind. 15 Schritte</li>"
                +"<li>5 EV => mind. 21 Schritte</li>"
                +"</ul>"
                + "</ol>"
                +"</html></ul>");

        Hint.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipp"));

        this.add(Hint, constraints);


        constraints.gridwidth = GridBagConstraints.RELATIVE;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridx = 1;
        constraints.gridy = 4;

        navigation.add(previous, constraints);
        navigation.add(getHelpButton(), constraints);
        navigation.add(next, constraints);

        constraints.gridwidth = GridBagConstraints.REMAINDER;

        this.add(navigation, constraints);

        this.setVisible(true);
    }

    public int getStepMode(){
        return learningRuleChooser.getSelectedIndex();
    }
    @Override
    public void writePropertysToFile(String prop){
        super.propertys.add(prop);
    }
    @Override
    public LinkedList<String>getPropertys(){
        return super.propertys;
    }

     public static void main(String[] args) {
        JFrame test = new JFrame();
        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        test.setPreferredSize(new Dimension(800, 800));

        Graph graph = new Graph();
        test.add(new StepModeChooserPanel());

        test.setResizable(false);
        test.pack();
        test.setVisible(true);
    }

//             @Override
//    public ActionListener getActionListener() {
//        return new ActionListener() {
//
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                System.out.println("Help from Learning Rule Chooser Panel");
//            }
//        };
//
//    }

             @Override
    public ActionListener getActionListener() {
        return new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                HelpWindowFactory.createHelpWindow(new HelpPanel("src/neuronalenetzeelearning/view/help/resources/Schrittmodus.png"));
            }
        };

    }
}
